package com.qixiucoding.learn_liu;


import org.junit.Test;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * @Description TODO
 * @Author longhj
 * @Date 2021/11/21 星期日 15:04
 */
public class LearnFileInputStream {
    @Test
    public void testFileInputStream1(){
            try {
                FileInputStream fileInputStream = new FileInputStream("c.txt");
                int read = fileInputStream.read();
                System.out.println(read);
                System.out.println((char)read);
                fileInputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
        }
    }
    @Test
    public void testFileInputStream2(){
        try {
            FileInputStream fileInputStream = new FileInputStream("c.txt");
            int read;
            byte[] b = new byte[2];
            while ((read = fileInputStream.read(b)) != -1) {
                System.out.println(read);
                System.out.println( new String(b,0,read) );

            }
            fileInputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
